package com.anotherbigidea.util.xml;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;



/**
 * Utilities for using the Apache Xerces XML Parser
 */
public class Xerces
{
    public static void parse( DefaultHandler handler, InputStream in ) 
        throws SAXException, IOException
    {
        
        InputSource source = new InputSource( in );
        
       	SAXParserFactory saxFactory = SAXParserFactory.newInstance();
        SAXParser parser = null;
        try{
        		parser = saxFactory.newSAXParser();
        }catch(javax.xml.parsers.ParserConfigurationException e){}
		
        XMLReader xmlReader = parser.getXMLReader();
  
        xmlReader.setContentHandler( handler );
        xmlReader.setErrorHandler( handler );        
        xmlReader.parse( source );
        
        in.close();
 

    
    }
}
